package com.travel.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qianfeng.util.ResultMsg;
import com.travel.entity.TbAdmin;
import com.travel.mapper.AdminMapper;
import com.travel.service.AdminService;
import org.springframework.stereotype.Service;

@Service
public class AdminServiceImpl extends ServiceImpl<AdminMapper,TbAdmin> implements AdminService {
    /**
     * 查询所有管理员
     * */
    @Override
    public ResultMsg getAllAdmin(int current, int size) {
        Page<TbAdmin> ipage = new Page<>(current,size);
        Page<TbAdmin> page = super.page(ipage);
        return ResultMsg.success(page);
    }
    /**
     * 通过id查询管理员
     * */
    @Override
    public ResultMsg getAdminById(int adminId) {
        TbAdmin byId = super.getById(adminId);
        if(byId==null){
            return  ResultMsg.error(555,"没有当前的汽车班次");
        }else {
            return ResultMsg.success(byId);
        }
    }
    /**
     * 修改管理员
     * */
    @Override
    public ResultMsg updateAdmin(TbAdmin tbAdmin) {
        boolean b = super.saveOrUpdate(tbAdmin);
        if (tbAdmin!=null)
            return ResultMsg.success(b);
        else
            return ResultMsg.error(555,"修改汽车票失败");
    }
    /**
     * 添加管理员
     * */
    @Override
    public ResultMsg addAdmin(TbAdmin tbAdmin) {
        boolean b = super.saveOrUpdate(tbAdmin);
        if (tbAdmin!=null)
            return ResultMsg.success(b);
        else
            return ResultMsg.error(555,"添加汽车票失败");
    }
    /**
     * 删除管理员
     * */
    @Override
    public ResultMsg deleteAdmin(int id) {
        boolean b = super.removeById(id);
        if (b)
            return ResultMsg.success(b);
        return ResultMsg.error(555,"删除失败");
    }
}
